package com.zmn.oms.business.impl.orderamount;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.zmn.base.common.data.common.dro.tags.TagsDRO;
import com.zmn.common.constant.GlobalConsts;
import com.zmn.oms.business.interfaces.base.BaseCodeService;
import com.zmn.oms.business.interfaces.orderamount.OrderAmountCheckBService;
import com.zmn.oms.model.entity.work.OrderWork;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * @author sunlife
 * @date:2022/1/13 3:19 下午
 * description:
 */
@Slf4j
@Service
public class OrderAmountCheckBServiceImpl implements OrderAmountCheckBService {

    @Resource
    protected BaseCodeService baseCodeService;

    @NacosValue(value = "${pay.sms.mobile.limit.codeId:8003}", autoRefreshed = true)
    private Integer MOBILE_LIMIT_CODE_ID;

    @NacosValue(value = "${pay.sms.mobile.disabled.input.cityIdList:0}", autoRefreshed = true)
    private List<Integer> cityIdList;

    @Override
    public Integer checkShowMobileInput(OrderWork orderWork) {

        TagsDRO baseCodeMapDRO = baseCodeService.getOneBaseCodeMap(GlobalConsts.PLAT_MARK_ZMN, MOBILE_LIMIT_CODE_ID, null);
        if (baseCodeMapDRO != null && StringUtils.isNotBlank(baseCodeMapDRO.getName()) &&
                Arrays.asList(baseCodeMapDRO.getName().split(",")).contains(String.valueOf(orderWork.getManageCompanyId()))
        ) {
            return GlobalConsts.NO;
        }

        if (cityIdList.contains(orderWork.getCityId())) {
            return GlobalConsts.NO;
        }

        return GlobalConsts.YES;
    }
}
